import java.awt.Color;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
 
public class MainMenuState extends BasicGameState {
 
    int stateID = -1;
    Image background = null;
    Image startGameOption = null;
    int startX = 664, startY = 470;
    float startGameScale = 1;
    Image exitOption = null;
    int exitX=44, exitY = 537;
    float exitScale = 1;
    Image l = null;
    int lX=181, lY = 172;
    float lScale = 1;
    Image b = null;
    int bX=81, bY = 77;
    float bScale = 1;
    Image credits = null;
    int creditsX=431, creditsY = 132;
    float creditsScale = 1;
	float scaleStep = 0.0001f;
    Image options= null;
    int optionsX = 320, optionsY = 100;
    Image k= null;
    int kX = 600, kY = 75;
    double colorG=0;
    boolean gradient;
    public MainMenuState( int stateID ) 
    {
       this.stateID = stateID;
    }//Ends constructor
 
    @Override
    public int getID() {
        return stateID;
    }//Ends getID
 
    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
        background = new Image("Data/mainmenu.jpg");
        startGameOption= new Image("Data/start.png");
        exitOption =new Image("Data/exit.png");
        b= new Image("Data/b.png");
        l = new Image("Data/l.png");
        credits = new Image("Data/cred.png");
        options= new Image("Data/option.png");
        k= new Image("Data/k.png");
        gradient=true;
    }//Ends init
 
    public void render(GameContainer gc, StateBasedGame sbg, Graphics gc1) throws SlickException {
    	background.draw(0, 0);
    	

		if(colorG>=200)	{
			gradient=false;
		}
		else if(colorG<=0.0){
			gradient=true;
		}	
		System.out.println(colorG);
	    if(gradient==true)
    	colorG+=0.03;
	    else if (gradient==false)
	    colorG-=0.03;
	 
    	gc1.setColor(new org.newdawn.slick.Color((int)(0+colorG),(int)(0+colorG),(int)(0+colorG)));
    	gc1.fillRect(startX-12, startY-6, 50, 50);
    	gc1.fillRect(optionsX-8, optionsY-7, 50, 50);
       	gc1.fillRect(lX-15, lY-6, 50, 50);
    	gc1.fillRect(creditsX-10, creditsY-7, 50, 50);
    	startGameOption.draw(startX, startY, startGameScale);
    	exitOption.draw(exitX, exitY, exitScale);
    	b.draw(bX, bY, bScale);
    	l.draw(lX, lY, lScale);
    	options.draw(optionsX, optionsY, bScale);
    	k.draw(kX, kY, lScale);
    	credits.draw(creditsX, creditsY, creditsScale);

    }//Ends render
 
    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    	Input input = gc.getInput();
    	int mouseX = input.getMouseX();
    	int mouseY = input.getMouseY();
    	boolean insideStartGame = false;
    	boolean insideExit = false;
    	if( ( mouseX >= startX && mouseX <= startX + startGameOption.getWidth()) &&
    	    ( mouseY >= startY && mouseY <= startY + startGameOption.getHeight()) ){
    	    insideStartGame = true;
    	}/*Ends if statement*/else if( ( mouseX >= exitX && mouseX <= exitX+ exitOption.getWidth()) &&
    	          ( mouseY >= exitY && mouseY <= exitY + exitOption.getHeight()) ){
    	    insideExit = true;
    	}//Ends else if statement    	 
    	if(insideStartGame){
    	  if(startGameScale < 1.05f)
    	    startGameScale += scaleStep * delta;
    	  if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
    	    sbg.enterState(BlocksGame.GAMEPLAYSTATE);
    	  }//Ends if statement
    	}/*Ends if statement*/else{
    	  if(startGameScale > 1.0f)
    	    startGameScale -= scaleStep * delta;
    	}//Ends else statement
    	if(insideExit)
    	{
    	   if(exitScale < 1.05f)
    	     exitScale +=  scaleStep * delta;
     	  if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) )
      	    gc.exit();
    	}/*Ends if statement*/else{
    	  if(exitScale > 1.0f)
    	    exitScale -= scaleStep * delta;
    	}//ends else statement
    }//Ends update
 
}//Ends MainMenuState